Skip to content

Leave out the empty ranges the out-of-process formatters get - #277

Merged
abashev merged 3 commits into
21.X.Xfrom
abashev/ioe-formattercommandrunner.runwithstdin
Nov 25, 2026
Merged

abashev merged 3 commits into
21.X.Xfrom
abashev/ioe-formattercommandrunner.runwithstdin

Conversation

@abashev

@abashev abashev commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Based on 21.X.X.

IntelliJ IDEA can pass an empty range among the ranges it reformats. The native and the separate-JVM services turned [n, n) into n:n-1, which --character-ranges rejects with Invalid range: [1376..1375], because its ranges are closed. Reformat then failed with the UncheckedIOException of #275. The in-process formatter never failed, since FormatterServiceImpl puts the ranges in a TreeRangeSet, which drops empty ones. The released 21.0.2 binary shows both halves: --character-ranges 10:20,22:21 exits 2, and no --character-ranges at all formats the whole file.

Changes

  • RangeUtils.toStringRanges leaves out the ranges that are empty once canonical, before they become --character-ranges.
  • NativeImageFormatterService and BootstrappingFormatterService return no replacements, without starting the command, when no range is left. That is what FormatterServiceImpl does; without the flag, the command line would format the whole file.
  • One behaviour changes beyond the crash. formatDiff drops the empty range of a blank line, so with the native or the separate-JVM formatter a diff that adds only blank lines reformatted the whole file. It now formats nothing there, as it already did in process.

The fix is in the bootstrap code, not the command line, so it also holds when the separate JVM runs an older formatter.

Checked

  • JvmFormatterServicesTest, which runs in every build, and FormatterServicesTest, which the native jobs run, each get two cases: an empty range in the middle of the file and one at its end, next to a range that is not empty, and empty ranges or no range alone. Before the fix both cases failed on the separate-JVM service with the issue's error.
  • ./gradlew -PnativeImage=true :open-java-format-jdk-bootstrap:test :gradle-open-java-format:test passes against a native binary built from this branch with GraalVM 25, and ./gradlew check passes.

CI runners

A second commit, unrelated to the fix:

  • CI's native job leaves out macOS on Apple silicon, commented out in its matrix. release.yml still builds it.
  • Every native leg moves to the newest image. That is macos-latest for Apple silicon. Arm Linux and Intel macOS have no free -latest label, so they get ubuntu-26.04-arm and macos-26-intel; macos-latest-large is Intel too, but it is a paid larger runner. mise run ci:native and the README follow.
  • release.yml's matrix lists the runners alone, as ci.yml's does: its platform names only named the jobs and their artifacts, which the runner label names now. The binaries are named, and their Maven classifiers read, from what Gradle builds.
  • The Linux binary links glibc dynamically, so the arm64 one built on 26.04 needs the glibc the x64 one has needed since ubuntu-latest moved to 26.04.

Closes #275

IntelliJ IDEA can pass an empty range among those it reformats. The
native and the separate-JVM services turned [n, n) into "n:n-1", which
--character-ranges, whose ranges are closed, rejects with "Invalid
range", and Reformat failed. FormatterServiceImpl, in process, already
leaves empty ranges out: its TreeRangeSet drops them.

The two services now leave them out too, and format nothing when no
range is left, as FormatterServiceImpl does: without --character-ranges
the command line would format the whole file. formatDiff, which drops
the empty range of a blank line, so no longer reformats the whole file
when a diff adds only blank lines.

Closes #275
CI's native job leaves out macOS on Apple silicon, commented out in its
matrix; release.yml still builds it. Every native leg moves to the
newest image: macos-latest for Apple silicon, and, as arm Linux and
Intel macOS have no free -latest label, ubuntu-26.04-arm and
macos-26-intel.
The platform names in release.yml's matrix only named the jobs and
their artifacts: the binaries are named, and their Maven classifiers
read, from what Gradle builds, and the deploy jobs collect every
native-image-* artifact. The runner label names both now.
@abashev
abashev merged commit 191f1c3 into 21.X.X Nov 25, 2026
11 checks passed
@abashev
abashev deleted the abashev/ioe-formattercommandrunner.runwithstdin branch November 25, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IOE: FormatterCommandRunner.runWithStdin

1 participant